import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd());
  const { VITE_BASE_URL_POST, VITE_BASE_IDENTIFY } = env;
  // console.log(env);
  return {
    define: {
      APPENV: JSON.stringify(env), // 替换为你的环境变量名
    },
    plugins: [vue()],
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "src"),
      },
    },
    base: "/command-centre-mobile/",
    server: {
      port: 5173,
      host: true,
      open: true,
      proxy: {
        // 处置响应接口
        '/cqwl': {
            target: VITE_BASE_URL_POST,
            changeOrigin: true
        },
        // 预警/辨识接口
        '/early-warning-web/api': {
          target: VITE_BASE_URL_POST,
          changeOrigin: true,
        },
        // 辨识接口
        '/api': {
            target: VITE_BASE_IDENTIFY,
            changeOrigin: true,
            rewrite: (p) => p.replace(/^\/api/, '')
        },
      }
    },
    build:{
      outDir: "command-centre-mobile"
    }
  }
});
